﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DetectiveCluedo
{
    public class GameLog
    {
        public Player MovePlayer;
        public Player DisapprovePlayer;
        public Card SuspectCard;
        public Card WeaponCard;
        public Card RoomCard;
        public Card ShownCard;

        private bool _isInitialized;
        public bool IsInitialized
    {
        get { return _isInitialized; }
    }

        // Some rules:
        // Move Player must be different from ConfirmPlayer
        // ShownCard must be one of the Suspect, Weapon, Room cards

        public GameLog(Player movePlayer, Player confirmPlayer, Card suspect, Card weapon, Card room, Card shownCard)
        {
            if (movePlayer.Equals(confirmPlayer))
            {
                MessageBox.Show("Move Player and Confirm Player must be different!");
                return;
            }

            if (suspect.Equals(weapon) || suspect.Equals(room) || weapon.Equals(room))
            {
                MessageBox.Show("Duplicate cards selected!");
                return;
            }

            if (movePlayer.IsYou && confirmPlayer != null && shownCard == null)
            {
                MessageBox.Show("If you are asking (move player) than you must have seen the card!");
                return;
            }

            if (!movePlayer.IsYou && confirmPlayer != null && !confirmPlayer.IsYou && shownCard != null)
            {
                MessageBox.Show("If you are not asking (move player) than you cannot see the card!");
                return;
            }

            if (shownCard != null && !shownCard.Equals(suspect) && !shownCard.Equals(weapon) && !shownCard.Equals(room))
            {
                    MessageBox.Show("Shown card must be one of the Suspect / Weapon / Room cards!");
                    return;
                }

            MovePlayer = movePlayer;
            DisapprovePlayer = confirmPlayer;
            SuspectCard = suspect;
            WeaponCard = weapon;
            RoomCard = room;
            ShownCard = shownCard;

            _isInitialized = true;
        }

        public override string ToString()
        {
            if(IsInitialized)
                return string.Format("{0} => {1},{2},{3} => {4} [{5}]", MovePlayer, SuspectCard, WeaponCard, RoomCard, (ShownCard != null)? ShownCard.ToString() : "");
            return "NOT INITIALIZED";
        }
    }
}
